#include <FindGUIEventHandlerByIdVisitor.h>
#include <SceneViewerFunctions.h>

FindGUIEventHandlerByIdVisitor::FindGUIEventHandlerByIdVisitor()
{
	_finded_gui_event_handler = NULL;
}

FindGUIEventHandlerByIdVisitor::~FindGUIEventHandlerByIdVisitor()
{

}

void FindGUIEventHandlerByIdVisitor::apply( osgViewer::Viewer& viewer )
{
	int i;
	int event_handler_size = SceneViewerFunctions::sceneViewerGetEventHandlerSize();
	for (i = 0; i < event_handler_size; i++)
	{
		osg::ref_ptr<osgGA::GUIEventHandler> handler_ptr = SceneViewerFunctions::sceneViewerGetEventHandler(i);
		if (SceneViewerFunctions::osgObjectGetDescription(handler_ptr, "id") == _id_string)
		{
			_finded_gui_event_handler = handler_ptr;
			return;
		}

	}

}

void FindGUIEventHandlerByIdVisitor::setIdString( const std::string& id_string )
{
	_id_string = id_string;
}

osg::ref_ptr<osgGA::GUIEventHandler> FindGUIEventHandlerByIdVisitor::getFindedGUIEventHandler()
{
	return _finded_gui_event_handler;
}
